package psd.model.Scala.Converters;

import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.Type;

import psd.model.IConverter;
import psd.scala.FactDb;
import psd.scala.ScalaConverter;
import psd.scala.facts.ClassDefT;

public class ScalaTypeDeclarationConverter extends ScalaConverter implements
		IConverter<TypeDeclaration> {

	public ScalaTypeDeclarationConverter(FactDb fdb) {
		super(fdb);
	}
	
	@Override
	public boolean convert(TypeDeclaration node) {
		
		MethodDeclaration[] methods = node.getMethods();
		
		List interfaces = node.superInterfaceTypes();
		String[] interfacesNames = new String[interfaces.size()];
		int i = 0;
		for (Iterator iterator = interfaces.iterator(); iterator.hasNext();) {
			Type type = (Type) iterator.next();
			 interfacesNames[i]= ((SimpleType) type).getName().toString();
			i++;
		}
		 
		boolean isAbstract = Modifier.isAbstract(node.getModifiers());
			
		/*ID, cantidad metodos, ruta de la clase, numero de linea.*/
		ClassDefT fact = new ClassDefT(node.hashCode(),
										this.getLineNumber(node), 
										this.getFilePath(node),
										methods.length,
										node.isInterface(), 
										isAbstract, interfacesNames);
		
		this.fdb.addClassDef(fact);
		return true;
	}

}
